<template>
	<view class="image-data" @tap="puctChange(item.id)" style="border-radius: 5px;background-color: #f8f8f8;">
		<image class="image" :src="sConf.pics + (item.cover ?? [])[0]?.url" mode="widthFix"
			style="background-color: #f1f1f1;border-radius: 5px 5px 0 0;" />
		<view style="padding: 0 10px 10px 10px;">
			<view class="title" style="font-weight: normal;"> {{ item.name }}</view>
			<view class="tags" style="display: flex;gap: 5px;padding: 5px 0;">
				<tn-tag v-for="(tag, index) in item.tag" :key="index" type="info" shape="round" font-size="20"
					:bg-color="tag.bgcolor" :text-color="tag.color">{{ tag.name }}</tn-tag>
			</view>
			<view
				style="padding: 10px 0;display: flex;flex-direction: row;justify-content: space-between;align-items: center;">
				<view class="price">
					<view v-if="item.is_money == 1">
						<tn-icon name="money" size="20px"></tn-icon>
						<text style="color: #dd524d;padding-left: 5px;">{{ (item.price.price / 100).toFixed(2)
							}}</text><text>元</text>
					</view>
					<view v-if="item.is_point == 1">
						<tn-icon name="funds" size="20px"></tn-icon>
						<text style="color: #007aff;padding-left: 5px;">{{ item.point }}</text>
					</view>
				</view>
				<!--
				<view class="buy" style="padding: 10px;" @tap.stop="cartChages(item.id)">
					 <tn-icon name="cart" size="32px"></tn-icon> 
				</view>
				-->
				<view style="padding: 10px;color: #999;">
					￥<text style="text-decoration: line-through;">{{ (item.price.money / 100).toFixed(2) }}</text>
				</view>
			</view>
			<view style="display: flex;justify-content: space-between;color: #999;font-size: small;">
				<view class=""> 销量: {{ item.hot }} </view>
				<view class=""> 库存: {{ item.cur_num }} </view>
			</view>
		</view>
		<!--收藏按钮-->
		<tn-icon :name="item.is_like ? 'like-lack-fill' : 'like-lack'" size="48"
			style="position: absolute;top: 0;right: 0;padding: 10px;" :class="item.is_like ? 'like-active' : 'like-normal'"
			@tap.stop="likeChange(item.id)"></tn-icon>
	</view>
</template>

<script>
import utils from '../../common/utils';

export default {
	name: "mallt-goods",
	data() {
		return {
			sConf: getApp().globalData,
		};
	},
	props: {
		item: {
			type: Object
		}
	},
	methods: {
		puctChange(e) {
			this.$emit('puctChange', e)
		},
		cartChages(e) {
			this.$emit('cartChages', e)
		},
		likeChange(e) {
			this.$emit('likeChange', e)
			this.item.is_like = !this.item.is_like;

			let host = this.sConf.host + '/weapps/favored/'
			let token = this.sConf.token
			let data = {
				sid: this.sConf.auth.id,
				puid: this.item.id,
				status: this.item.is_like ? 1 : 0
			}
			utils.authenticatorPost(host, token, data).then((res) => {
				console.log('切换收藏夹');
			})
		}
	}
}
</script>

<style lang="scss" scoped>
/* 产品列表 */
.image-data {
	position: relative;
	width: calc(100% - 20rpx);
	margin: 10rpx;

	.image {
		width: 100%;
		height: auto;
	}

}


/* 收藏选中 */
.like-active {
	color: #dd524d;
}

.like-normal {
	color: #000;
}
</style>